package com.yzh.wanandroid.base

import androidx.activity.viewModels
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

abstract class MvvmActivity<V : ViewDataBinding, VM : ViewModel>: BaseActivity<ViewDataBinding>() {

    protected lateinit var mViewModel: VM

    abstract fun initViewModel(): VM

    /**
     * 创建ViewModel实例
     */
    inline fun <reified VM : ViewModel> createViewModel(): VM {
        return viewModels<VM> { ViewModelProvider.AndroidViewModelFactory(application) }.value
    }
}